// 引入Count的UI组件
import CountUI from '../../components/Count/Count'; 

//引入connect用于连接UI组件与redux
import { connect } from 'react-redux'

import {
    createIncrementAction,
    createDecrementAction,
    createDecrementSyncAction
} from '../../redux/count_action';

/*
    1.mapStateToProps函数返回的是对象；
    2.返回的对象中key就作为传递给UI组件props的key, value就租完传递给UI组件props的value
    3.mapStateToProps用于传递状态
*/
const mapStateToProps = (store) => {
    return {count:store}
}

/*
    1.mapDispatchToProps函数返回的是对象；
    2.返回的对象中key就作为传递给UI组件props的key, value就租完传递给UI组件props的value
    3.mapStateToProps用于传递操作状态的方法
*/
const mapDispatchToProps = (dispatch) => {
    return {
        increment: number => dispatch(createIncrementAction(number)),
        decrement: number => dispatch(createDecrementAction(number)),
        syncDecrement:(number,time) => dispatch(createDecrementSyncAction(number,time)),
    }
}

// 使用connect()()创建并暴露一个Count的容器组件
export default connect(mapStateToProps,mapDispatchToProps)(CountUI)